﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Drawing;
using System.IO;
using System.Drawing.Imaging;
using System.Windows.Forms;

namespace DotNet.Practico1.UI.Support
{
    public static class Utils
    {
        public static Image BinaryToImage(Byte[] image)
        {
            if (image != null)
            {
                Byte[] byteBLOBData = new Byte[0];
                byteBLOBData = image;
                MemoryStream stream = new MemoryStream(byteBLOBData);
                if (stream.Length > 0)
                    return Image.FromStream(stream);
            }
            return null;
        }

        public static byte[] ImageToBinary(Image image)
        {
            MemoryStream stream = new MemoryStream();
            if (image != null)
            {
                image.Save(stream, ImageFormat.Jpeg);
            }
            return stream.ToArray();
        }

        public static DialogResult RequestConfirmation(string texto)
        {
            return MessageBox.Show(texto, "Confirmación", MessageBoxButtons.YesNo, MessageBoxIcon.Question);
        }

        public static void DisplayError(string texto)
        {
            MessageBox.Show(texto, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
        }
    }
}
